package com.sia.springcloud.controller;

import com.sia.springcloud.service.IFileParseService;
import com.sia.springcloud.service.impl.FileParseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: Sirius
 * @Date: 2022/1/10 13:48
 * @Description:
 **/
@Slf4j
@RestController
@RequestMapping("//fileParseController")
public class FileParseController {

    @Resource
    private IFileParseService fileParseService;

    /**
     * 使用excel下载点位信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/downloadExcelTemplate")
    public String downloadExcelTemplate(HttpServletResponse response,HttpServletRequest request){
        log.info("使用excel下载点位信息");
        String protocolName = request.getParameter("protocolName");
        String type = request.getParameter("type");

        fileParseService.downloadExcelTemplate(response,protocolName,type);
        return null;
    }

    /**
     * 使用excel上传设备信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/uploadDeviceExcel")
    public String uploadDeviceExcel(HttpServletRequest request, @RequestParam("file")MultipartFile excelFile) {
        log.info("使用excel上传设备信息");
        String result = fileParseService.uploadDeviceExcel(request, excelFile);
        return result;
    }

    /**
     * 使用excel上传点位信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/uploadPointExcel")
    public String uploadPointExcel(HttpServletRequest request,  @RequestParam("file")MultipartFile excelFile) {
        log.info("使用excel上传点位信息");
        String result = fileParseService.uploadPointExcel(request, excelFile);
        return result;
    }


}
